package com.cidp.system.dao.impl;

import java.util.Date;
import java.util.List;

import com.cidp.system.dao.IOpLogDao;
import com.cidp.system.model.TopLog;
import com.cidp.system.pojo.OpLogPo;
import com.litt.core.common.Utility;
import com.litt.core.dao.BaseDaoImpl;
import com.litt.core.page.IPageList;
import com.litt.core.page.PagePoParam;

/**
 * <b>标题：</b>日志查询DAO实现.
 * 
 * <pre>
 * &lt;b&gt;描述&lt;/b&gt;
 *    日志查询
 * </pre>
 * 
 * @author lijian
 * @since 2008-5-23
 * @version 1.0
 */
public class OpLogDaoImpl extends BaseDaoImpl implements IOpLogDao {

	/**
	 * 读取日志信息
	 * 
	 * @param topId 日志ID
	 * @return TopLog对象
	 */
	public TopLog loadById(Long topId){
		return (TopLog) super.loadObject(TopLog.class, topId);
	}

	/**
	 * 删除日志信息.
	 * 
	 * @param topLog 日志对象
	 */
	public void deleteTopLog(TopLog topLog){
		super.deleteObject(topLog);
	}

	/**
	 * 保存日志信息.
	 * 
	 * @param topLog 日志对象
	 * @return 主键
	 */
	public Long saveTopLog(TopLog topLog){
		return super.saveObject(topLog);
	}

	/**
	 * 更新日志信息.
	 * 
	 * @param topLog 日志对象
	 */
	public void updateTopLog(TopLog topLog){
		super.updateObject(topLog);
	}
	
	/**
	 * 根据时间时间和操作员Id查询对象
	 * 
	 * @param startDate 开始时间
	 * @param endDate	结束时间
	 * @param opId		操作员Id
	 * 
	 * @return TopLog对象列表
	 */
	public List listByOpDatetimeAndOpId(Date startDate,Date endDate,Long opId){
		String listHql = " from TopLog where opDatetime between ? and ? and opId=?";
		return super.listAll(listHql, new Object[]{startDate,endDate,opId});
	}
	
	/**
	 * 分页查询操作日志信息.
	 * 
	 * @param pagePoParam 查询参数
	 * @return IPageList IPageList对象
	 */
	public IPageList listByPage(PagePoParam pagePoParam) {
		OpLogPo opLogPo = (OpLogPo) pagePoParam.getConds();
		StringBuffer listHql = new StringBuffer("from TopLog opLog,Toperator operator where 1=1 and opLog.opId=operator.opId ");
		StringBuffer listCountHql = new StringBuffer("select count(*) from TopLog opLog,Toperator operator where 1=1 and opLog.opId=operator.opId ");
		StringBuffer condition = new StringBuffer(" ");
		if(! Utility.isEmpty(opLogPo.getStartDate()) && ! Utility.isEmpty(opLogPo.getEndDate())){
			condition.append(" and opLog.opDatetime between ");
			condition.append(Utility.parseDate(opLogPo.getStartDate()));
			condition.append(" and ");
			condition.append(Utility.parseDate(opLogPo.getEndDate()));
		}
		if(! Utility.isEmpty(opLogPo.getFuncCode())){
			condition.append(" and opLog.funcCode like '%");
			condition.append(opLogPo.getFuncCode());
			condition.append("%'");
		}
		if(! Utility.isEmpty(opLogPo.getOpName())){
			condition.append(" and operator.opName like '%");
			condition.append(opLogPo.getOpName());
			condition.append("%'");
		}
		if(opLogPo.getLoginId() != null){
			condition.append(" and operator.loginId like '%");
			condition.append(opLogPo.getLoginId());
			condition.append("%'");
		}
		return super.listHqlPage(listHql.toString(), listCountHql.toString(),pagePoParam.getPageIndex(), pagePoParam.getPageSize());
	
	}
	
}
